﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using NHibernate.Cfg.MappingSchema;

namespace MVCGen.Generators.Entity {
	public class HbmListFieldGenerator : ICodeTypeMemberGenerator {
		private HbmList list;
		private ICodeTypeMemberGenerator elementGenerator;

		public HbmListFieldGenerator(HbmList list) {
			this.list = list;
			if (list.Item1 is HbmOneToMany)
				elementGenerator = new HbmOneToManyFieldGenerator(list.name, list.Item1 as HbmOneToMany);
			else if (list.Item1 is HbmElement)
				elementGenerator = new HbmElementFieldGenerator(list.name, list.Item1 as HbmElement);
			else if (list.Item1 is HbmManyToMany)
				elementGenerator = new HbmManyToManyFieldGenerator(list.name, list.Item1 as HbmManyToMany);
			else if (list.Item1 is HbmCompositeElement)
				elementGenerator = new HbmCompositeElementFieldGenerator(list.name, list.Item1 as HbmCompositeElement);
			else if (list.Item1 is HbmManyToAny)
				elementGenerator = new HbmManyToAnyFieldGenerator(list.name, list.Item1 as HbmManyToAny);
			else
				throw new ArgumentException(String.Format("Unsupported bag item {0}", list.Item1.GetType().Name));
		}

		public CodeTypeMember Generate() {
			return elementGenerator.Generate();
		}
	}
}
